package seedswapapplication
/*
 * ClientController is the main controller for navigating between pages in the user interface. 
 * Any intermediate pages that do not need access to the database are handled in ClientController
 */
class ClientController {
	/*
	 * The login action directs to the login.gsp page for a user to log in.
	 */
	def login = 
	{
		if(session.username)
		{
			flash.message = "You must be logged out to log in. Please log out."
			redirect(url:"/")
		}
	}
	
	/*
	 * The register action directs to the the page for a new farmer to register
	 */
	def register = 
	{
		if(session.username)
		{
			flash.message = "You must be logged out to register. Please log out."
			redirect(url:"/")
		}
	}
	
	
	/*
	 * This action directs to the home page for administrators
	 */
	def adminPage = 
	{
		if(!session.isAdmin)
		{
			flash.message = "You must be logged in as an admin to access this page."
			redirect(url:"/")
		}
	}
	
	
	/*
	 * This action directs to a page with a form for creating a new seed
	 */
	def createSeedPage = 
	{
		if(!session.username)
		{
			flash.message = "You must be logged in to offer seeds. Please log in or register."
			redirect(url:"/")
		}
	}
	
	/*
	 * This action directs to a page with a form for searching for seeds by scientific name or hardiness zone
	 */
	def searchSeedPage = {}
	
	/*
	 * This action resets all necessary session variables to ensure no one is logged in
	 */
	def logout = 
	{
		session.isAdmin=false
		if(session.username)
		{
			redirect(url:"/")
			flash.message = "Goodbye ${session.username}"
			session.loggedInMessage = null
			session.username = null
		}
		else
		{
			flash.message = "You are not logged in."
			redirect(url:"/")
		}	
	}
	
	
	
	
	
}
